home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / ANSI Headers / iomanip < prev    next >
Encoding:
Text File  |  1994-10-20  |  2.2 KB  |  99 lines  |  [TEXT/MMCC]

  1. // iomanip standard header
  2. #ifndef _IOMANIP_
  3. #define _IOMANIP_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9. #endif
  10.  
  11.         // template class smanip
  12. template<class _T> class smanip {
  13. public:
  14.     smanip(ios& (*_F)(ios&, _T), _T _A)
  15.         : _Pf(_F), _Manarg(_A) {}
  16.     ios& (*_Pf)(ios&, _T);
  17.     _T _Manarg;
  18.     };
  19. template<class _T> inline
  20.     istream& operator>>(istream& _I, const smanip<_T>& _M)
  21.     {    // apply manipulator to input stream
  22.     _TRY_BEGIN
  23.         (*_M._Pf)(_I, _M._Manarg);
  24.     _CATCH_ALL
  25.         _I.setstate(ios::failbit);
  26.     _CATCH_END
  27.     return (_I);
  28.     }
  29. template<class _T> inline
  30.     ostream& operator<<(ostream& _O, const smanip<_T>& _M)
  31.     {    // apply manipulator to output stream
  32.     _TRY_BEGIN
  33.         (*_M._Pf)(_O, _M._Manarg);
  34.     _CATCH_ALL
  35.         _O.setstate(ios::failbit);
  36.     _CATCH_END
  37.     return (_O);
  38.     }
  39.         // template class imanip
  40. template<class _T> class imanip {
  41. public:
  42.     imanip(istream& (*_F)(istream&, _T), _T _A)
  43.         : _Pf(_F), _Manarg(_A) {}
  44.     istream& (*_Pf)(istream&, _T);
  45.     _T _Manarg;
  46.     };
  47. template<class _T> inline
  48.     istream& operator>>(istream& _I, const imanip<_T>& _M)
  49.     {    // apply input manipulator to input stream
  50.     _TRY_BEGIN
  51.         (*_M._Pf)(_I, _M._Manarg);
  52.     _CATCH_ALL
  53.         _I.setstate(ios::failbit);
  54.     _CATCH_END
  55.     return (_I);
  56.     }
  57.         // template class omanip
  58. template<class _T> class omanip {
  59. public:
  60.     omanip(ostream& (*_F)(ostream&, _T), _T _A)
  61.         : _Pf(_F), _Manarg(_A) {}
  62.     ostream& (*_Pf)(ostream&, _T);
  63.     _T _Manarg;
  64.     };
  65. template<class _T> inline
  66.     ostream& operator<<(ostream& _O, const omanip<_T>& _M)
  67.     {    // apply manipulator to output stream
  68.     _TRY_BEGIN
  69.         (*_M._Pf)(_O, _M._Manarg);
  70.     _CATCH_ALL
  71.         _O.setstate(ios::failbit);
  72.     _CATCH_END
  73.     return (_O);
  74.     }
  75.         // instantiations
  76. smanip<ios::fmtflags> resetiosflags(ios::fmtflags);
  77. smanip<ios::fmtflags> setiosflags(ios::fmtflags);
  78. smanip<int> setbase(int);
  79. smanip<int> setfill(int);
  80. smanip<int> setprecision(int);
  81. smanip<int> setw(int);
  82.  
  83. #if __MWERKS__
  84. #pragma options align=reset
  85. #endif
  86.  
  87. #endif
  88.  
  89. /*
  90.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  91.  * Consult your license regarding permissions and restrictions.
  92.  */
  93.  
  94. /* Change log:
  95.  *94June04 PlumHall baseline
  96.  *94Sept30 Applied diffs for Fri Aug 26 00:52:06 1994
  97.  *94Oct07 Inserted MW changes.
  98.  */
  99.